package com.graduation.apiservice.controller;

import com.graduation.common.domain.dto.PageDTO;
import com.graduation.common.utils.UserContext;
import com.graduation.pojo.po.Comment;
import com.graduation.pojo.query.FrontCommentQuery;
import com.graduation.pojo.vo.FrontCommentVO;
import com.graduation.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

    private final CommentService commentService;

    /**
     * 分页查询评论（前台接口）
     */
    @GetMapping("/page")
    public PageDTO<FrontCommentVO> pageComments(FrontCommentQuery query) {
        return commentService.pageFrontComments(query);
    }

    @PostMapping("/addComment")
    public void saveComment(@RequestBody Comment comment) {
        Long userId = UserContext.getUser();
        comment.setUserId(userId);
        commentService.saveComment(comment);
    }

}
